package test.through.tree;

import java.math.BigDecimal;

import hyl.base.flow.chart.CNode;
import hyl.base.flow.chart.CWorkOrd;
import hyl.base.flow.chart.INode;
import hyl.base.flow.chart.IWorkOrd;
import hyl.base.flow.chart.IWorker;
import hyl.core.MyFun;
import hyl.core.MyMath;
import jnr.ffi.Struct.int16_t;

public class CworkTreeRwdTJ implements IWorker  {

	private final String CONSUME = "charge"; // 对应数据库.表.字段
	private final String NAME = "推荐奖"; // 定义奖金名称
	BigDecimal x = MyMath.BD1;
	BigDecimal y = MyMath.BD0;
	int count=0;




	private void setRwd(CNode u) {
		CNode p = (CNode) u.getParent();
		if (p == null) {
			return;
		}
		BigDecimal tjj = x.multiply(y);
		Creward r = new Creward();
		r.setWho(p.getId());
		r.setHowmuch(tjj.toPlainString());
		r.setSubject(count + "代" + this.NAME);
		//r.setRemark("来自" + first.getId());
		r.setTime(MyFun.getNow());
		//p.setEvent(r.getSort(), r);
	//	System.out.println(r);
	}

	@Override
	public Object run(INode 当前节点,IWorkOrd 待加工对象,Object ...其他参数) throws Exception {
		switch (count) {
		case 0:
			x = new BigDecimal(当前节点.getAttr(CONSUME).toString());
			y = BigDecimal.valueOf(0.01);
			break;
		case 1:
			y = BigDecimal.valueOf(0.05);
			break;
		case 2:
			y = BigDecimal.valueOf(0.03);
			break;
		default:
			y = MyMath.BD0;
			return true;
		}
		count++;
		setRwd((CNode) 当前节点);
		return false;
	}


}
